layout (location = 0) out vec4 eceGlPosition;
layout (location = 1) out vec4 eceGlNormal;
layout (location = 2) out vec4 eceGlAlbedoSpec;
layout (location = 3) out vec4 eceGlGameData;

uniform float distance;
uniform ece_Material material;
uniform sampler2D noise;
uniform sampler2D backTexture;
uniform samplerCube skybox;
uniform vec3 cameraPosition;
varying vec2 vTexCoord;
varying vec3 vPosition;
varying vec4 vGlPosition;
varying float vDistance;
varying mat3 vTBN;
void main() {
	vec3 normal = normalize(texture2D(noise, vec2(vTexCoord.x + distance, vTexCoord.y)).rbg  * 2.0 - 1.0);
	vec2 vGlTexCoord = (vGlPosition.xy / vGlPosition.w + 1) / 2;
	vec4 color = texture2D(backTexture, vGlTexCoord);
	//反射
	vec3 I =  normalize(vPosition - cameraPosition);
	vec3 R = reflect(I, normal);
	
	//float ratio = 1.00 / 1.52;
    //vec3 ZI = normalize(vPosition - cameraPosition);
    //vec3 ZR = refract(I, normal, ratio);
    
	vec4 baseColor = mix(color, textureCube(skybox, R), material.alpha);
	
	eceGlPosition.rgb = vPosition;
	eceGlPosition.a = vDistance;
	eceGlNormal.rgb = vTBN * normal;
	eceGlNormal.a = material.shininess;
	eceGlAlbedoSpec.rgb = baseColor.rgb * material.diffuse;
	eceGlAlbedoSpec.a = material.specular.r;
	//可以进行贴花
	eceGlGameData.r = 1.0;
}